class Node {
    constructor(e) {
        this.element = e;
        this.next = null;
    }
}

class LinkedList {
    constructor() {
        this.head = new Node('head');
    }
    find(item) {
        let currNode = this.head;
        while (currNode.element != item) {
            currNode = currNode.next;
        }
        return currNode;
    }
    findPrevious(item) {
        let currNode = this.head;
        while (currNode.next != null && currNode.next.element != item) {
            currNode = currNode.next;
        }
        return currNode;
    }
    insert(newElement, item) {
        let newNode = new Node(newElement);
        let currNode = this.find(item);
        newNode.next = currNode.next;
        currNode.next = newNode;
    }
    remove(item) {
        let prevNode = this.findPrevious(item);
        if (prevNode.next != null) {
            prevNode.next = prevNode.next.next;
        }
    }
    display() {
        let currNode = this.head;
        while (currNode.next != null) {
            console.log(currNode.next.element);
            currNode = currNode.next;
        }
    }
}